﻿using PdfSharp.Drawing;
using System.Collections.Generic;
using VAdvantage.Utility;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace VAdvantage.Print
{
    public class HeaderFooter
    {
        public HeaderFooter(Ctx ctx)
        {
            m_ctx = ctx;
        }	//	HeaderFooter

        /**	Ctx						*/
        private Ctx m_ctx;

        /**	Header/Footer content			*/
        private List<PrintElement> m_elements = new List<PrintElement>();
        /** Header/Footer content as Array	*/
        private PrintElement[] m_pe = null;


        public void AddElement(PrintElement element)
        {
            if (element != null)
                m_elements.Add(element);
            m_pe = null;
        }	//	addElement

        public PrintElement[] GetElements()
        {
            if (m_pe == null)
            {
                m_pe = new PrintElement[m_elements.Count];
                m_pe = m_elements.ToArray();
            }
            return m_pe;
        }	//	getElements


        public void PaintPdf(PdfSharp.Drawing.XGraphics g2D, XRect bounds, bool isView)
        {
            XPoint pageStart = new XPoint(bounds.X, bounds.Y);
            GetElements();
            for (int i = 0; i < m_pe.Length; i++)
                m_pe[i].PaintPdf(g2D, 0, pageStart, m_ctx, isView);
        }

        public void Paint(Canvas g2D, Rectangle bounds, bool isView)
        {
            Point pageStart = new Point(bounds.Margin.Left, bounds.Margin.Top);
            GetElements();
            for (int i = 0; i < m_pe.Length; i++)
                m_pe[i].Paint(g2D, 0, pageStart, m_ctx, isView);
        }	//	paint
    }
}
